package servlet;

import dao.BillDao;
import dao.CardDao;
import dao.StudentDao;
import pojo.Bill;
import pojo.Card;
import pojo.Student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author konley
 * @date 2020-06-10 22:59
 */
@WebServlet("/BillServlet")
public class BillServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String m = request.getParameter("m");
        if(m.equals("select")){
            int cid = Integer.parseInt(request.getParameter("cid"));
            List<Bill> bills = new BillDao().getBillsByCid(cid);
            request.setAttribute("bills",bills);
            request.getRequestDispatcher("/studentBill.jsp").forward(request,response);
        }else if(m.equals("backStu")){
            int cid = Integer.parseInt(request.getParameter("cid"));
            int sid = new CardDao().getSid(cid);
            Student stu = new StudentDao().getById(sid);
            request.getSession(true).setAttribute("student",stu);
            request.getRequestDispatcher("/studentView.jsp").forward(request,response);
        }
    }

}
